/**
 * 
 */
package cn.ac.istic.lkt.atv;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * @author scd
 *
 */
public class SentenceListPanel extends JPanel{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private FrmAbstract app;
	private JList list;
    DefaultListModel model;
    List<String> sen;
    
    public SentenceListPanel(FrmAbstract a){
    	app = a;
    	sen = new ArrayList<String>();
    	sen.add("  sentences");
        setLayout(new BorderLayout());
        model = new DefaultListModel();
        buildModel();
        list = new JList(model);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(7);
        list.setFont(TreePanelAbstract.TFONT);
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent evt) {
              int id = list.getSelectedIndex();
              paintTree(id);
              //System.out.println("Selected " + evt.getLastIndex());
            }
          });

        JScrollPane pane = new JScrollPane(list);
        add(pane, BorderLayout.NORTH);        
    }
    public void buildModel(){
    	model.removeAllElements();
        for (int i=0; i<sen.size(); i++){
        	model.addElement(sen.get(i));
        }

    }
    public void paintTree(int id){
    	if(id >= model.size()){
    		System.err.println("SentenceListPanel.java: list index out of Bound.");
    		return;
    	}
    	app.drawTree(id);
    	//tsen = sen
    	
    }
    public DefaultListModel getModel() {
		return model;
	}

	public void setModel(DefaultListModel model) {
		this.model = model;
	}

	public JList getList() {
		return list;
	}
	public void setList(JList list) {
		this.list = list;
	}
	public List<String> getSen() {
		return sen;
	}

	public void setSen(List<String> sen) {
		this.sen = sen;
	}
	

}
